package variabilitysmelldetection.measurement.measures.method;

import java.util.List;

import variabilitysmelldetection.measurement.measures.Measure;
import variabilitysmelldetection.measurement.models.ComponentItem;
import variabilitysmelldetection.measurement.models.MethodItem;



public class NumberOfMethodRefinements extends Measure {

	public NumberOfMethodRefinements() {
		super("Number of Method Refinements", "NMR");
	}

	public void measure(List<ComponentItem> items){
		int numOfRefinements = 0;
		List<MethodItem> methods = null;
		for (ComponentItem classe : items) {

			methods = classe.getMethods();

			for (MethodItem method : methods) {
				numOfRefinements = 0;

				if (!method.isRefinement()) {

					for (ComponentItem c : items) {
						
						if (c.isRefinement()) {
							
							for (MethodItem m : c.getMethods()) {
	
								if (m.isRefinement() && 
										m.getName().equals(method.getName()) &&
										c.getName().equals(classe.getName())) {
									numOfRefinements++;
								}
							}
						}
					}
				}
				NumberOfMethodRefinements nmr = new NumberOfMethodRefinements();
				nmr.setValue(numOfRefinements);
				method.addMeasure(nmr);
			}
		}
	}
}
